class Motor
	attr_reader :speed, :speedSp, :rampValue , :rampInterval, :inverted, :name, :ramping, :currentSpeedSp, :useRamping
	attr_writer :speedSp, :rampValue , :rampInterval, :inverted, :useRamping
	
   # added a line to check if commit hook funcitons 
   
   
      
   
	def initialize(name)
		@name=name
		@oldSpeed=0
		@currentSpeedSp=0
		@speedSp=0
		@rampInterval=0.001
		@rampValue=4
      @outputSpeed=nil
      @outputDir = nil
		@ramping = false
      @useRamping = true
		@@className = self.class.to_s.upcase+": "
		@@className = @@className.ljust(10)
		
		msg "Created a motor: "+@name
		
		@rampThread = Thread.new {ramper}
	end
	
        def attachOutput(myoutput)
          if(myoutput.type.upcase=="AO")
            # speed output
            @outputSpeed = myoutput
          elsif
            # dir output
            @outputDir = myoutput
          end
        end
        
        def speedOut
          if(@outputSpeed!=nil)
            if(@currentSpeedSp<0)
              @outputDir.set(1)
              @outputSpeed.set(@currentSpeedSp.abs)
            else
              @outputDir.set(0)
              @outputSpeed.set(@currentSpeedSp.abs)
            end
          end
        end
        
	def speedSp=(newSpeedSp)  
      if(@useRamping)
   		@oldSpeed=@speedSp
   		@speedSp = newSpeedSp
   		msg "Start ramping from "+@currentSpeedSp.to_s+" to "+@speedSp.to_s
      elsif
            @currentSpeedSp=newSpeedSp
            @speedSp=newSpeedSp
            speedOut
      end
	end  

	def msg(message)
		puts @@className+@name+": "+message
	end
	def Sensor.msg(message)
		puts @@className+message
	end
	
	def ramper
		while(1)
         while(@useRamping)
   			if (@currentSpeedSp<@speedSp)
   				#msg "RAMP UP"
   				@ramping = true
   				@currentSpeedSp += @rampValue
   				if(@currentSpeedSp>@speedSp)
   					@currentSpeedSp=@speedSp
   					@ramping=false
   				end
   			end
   			
   			if (@currentSpeedSp>@speedSp)
   				#msg "RAMP DOWN"
   				@ramping = true
   				@currentSpeedSp -= @rampValue
   				if(@currentSpeedSp<@speedSp)
   					@currentSpeedSp=@speedSp
   					@ramping=false
   				end
   			end
            speedOut
   			sleep @rampInterval
   		end #end while(@useRamping)
         sleep 2
      end # end while(1)
	end #end def

	
end